<?php

include_once "includes.php";
include_once "libs/auxiliares2.php";
include_once "libs/Sajax.php";
include_once "app/traerParametros.php";

$Servicio = new servicio();

$internos = $Servicio->find_by_interno(true);
$externos = $Servicio->find_by_interno(false);

?>

<?

function getConnections()
{
	$orq_ = new orquestacion();
	$conn_ = new connection();

	$orqs = $orq_->find_All();
	$i = 1;
	
	foreach($orqs as $orq)
	{
		$params = null;
		$conns = $conn_->find($orq->id);
		foreach($conns as $conn)
		{
			$tipo = getTipo($conn->tipo);
			$params = $params." ($tipo -> $conn->n1 : $conn->n2)";
		}
		
	    echo "<option value=$orq->id>$i => ($orq->n1 --> $orq->n2) <--> ($params )</option>";
		$i++;
	}
}

?>


<script type="text/javascript">
<?
	sajax_show_javascript();
?>

function CrearSelect(id_,salida, disabled) 
{
	var selectDestino=document.getElementById(id_);
	
	if (salida != "nulo" && !disabled)
	{
		var sel = '<select name=\"'+id_+'\" id=\"'+id_+'\">';
		sel = sel+'<option value=\"0\">Elige</option>';
		sel = sel+salida;
		sel = sel+'</select>';
		selectDestino.parentNode.innerHTML= sel;
	}
	else
	{
		var sel = '<select disabled="disabled" name=\"'+id_+'\" id=\"'+id_+'\">';
		sel = sel+'<option value="0">Selecciona opci&oacute;n...</option>';
		sel = sel+'</select>';
		selectDestino.parentNode.innerHTML= sel;
	}
}

function doLlenarCombosDesde(salida) 
{		
	count = salida.substring(0,1);
	txt = salida.substring(2,salida.length);
	//alert(count+'\n'+txt); 	
	
	for ( i=1;i<=3;i++)
	{
		var id_ = 'desde'+i;
		var disabled = true;
		if ( count > 0 ) var disabled = (i>count);
		CrearSelect(id_,txt, disabled)
	}
}

function doLlenarCombosHasta(salida) 
{		
	count = salida.substring(0,1);
	txt = salida.substring(2,salida.length);
//	alert(count+'\n'+txt); 	
	
	for ( i=1;i<=3;i++)
	{
		var id_ = 'hasta'+i;
		var disabled = true;
		if ( count > 0 ) var disabled = (i>count);
		CrearSelect(id_,txt, disabled)
	}
}

function LlenarCombos(srvId, cmbId)
{	
	var donde = null;
	(cmbId == "desde") ? donde = doLlenarCombosDesde : donde = doLlenarCombosHasta;
	
	var list=new Array();
	list[0]=srvId;
	list[1]=cmbId;
//	alert(list);	
	
	x_traerParametros(list, donde);
}

</script>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Simulador SOA</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<style type="text/css">
<!--
.header {
	font-size: 36px;
	font-weight: bold;
	color: #FFFFFF;
}
body,td,th {
	font-family: Arial, Helvetica, sans-serif;
	font-size: 12px;
	color: #333333;
}
.style2 {
	font-size: 14px;
	font-weight: bold;
}
-->
</style>
</head>
<body bgcolor="#FFFFFF">
<!-- ImageReady Slices (Untitled-2 copy) -->
<table width="800" border="0" align="center" cellpadding="0" cellspacing="0" id="Table_01">
	<tr>
		<td>
			<img id="index_01" src="images/index_01.jpg" width="747" height="36" alt="" /></td>
		<td><img id="index_02" src="images/index_02.jpg" width="53" height="36" border="0" alt="" /></td>
	</tr>
	<tr>
		<td height="93" colspan="2"><table width="100%"  border="0" cellpadding="0" cellspacing="0" background="images/header.gif">
          <tr>
            <td height="93"><table width="98%"  border="0" cellspacing="0" cellpadding="0">
              <tr>
                <td width="14%">&nbsp;</td>
                <td width="86%" class="header">Simulador SOA</td>
              </tr>
              <tr>
                <td>&nbsp;</td>
                <td><font color="#FFFFFF">Composici&oacute;n Est&aacute;tica de 
                  Servicios</font></td>
              </tr>
            </table></td>
          </tr>
        </table></td>
  </tr>
	<tr>
		<td height="33" colspan="2"><table width="100%"  border="0" cellpadding="0" cellspacing="0" background="images/nav.jpg">
          <tr>
            <td height="33">&nbsp;</td>
          </tr>
        </table></td>
  </tr>
	<tr>
		<td colspan="2"><table width="100%"  border="0" align="center" cellpadding="0" cellspacing="0" background="images/main.jpg">
          <tr>
            <td width="27%" valign="top"><table width="90%"  border="0" align="center" cellpadding="0" cellspacing="2">
              <tr> 
                <td align="center"><p><span class="style2">Navegaci&oacute;n</span></p>
                  <p>&nbsp;</p></td>
              </tr>
              <tr> 
                <td>&nbsp;<a href="index.php">Inicio</a></td>
              </tr>
              <tr> 
                <td>&nbsp;<a href="interfaces.php">Interfaces</a></td>
              </tr>
              <tr> 
                <td>&nbsp;<a href="metadata.php">Metadata</a></td>
              </tr>
              <tr> 
                <td>&nbsp;<a href="services.php">Servicios</a></td>
              </tr>
              <tr> 
                <td>&nbsp;<a href="static_comp.php">Composici&oacute;n Est&aacute;tica</a></td>
              </tr>
              <tr> 
                <td>&nbsp;</td>
              </tr>
              <tr> 
                <td><p><strong> </strong></p></td>
              </tr>
            </table></td>
            <td width="73%" valign="top"><table width="98%"  border="0" cellpadding="0" cellspacing="2">
              <tr> 
                <td><div align="center"> 
                    <p><font size="6">Composici&oacute;n Est&aacute;tica de Servicios</font></p>
                    <p align="left">En este paso, podr&aacute; organizar los servicios 
                      de manera de generar el flujo deseado de datos.</p>
                    <p align="left">En primer lugar debe ir conectado las salidas 
                      de los servicios con las entradas de otros, generando el 
                      flujo de esta manera.</p>
                    <p align="left">NOTA: para que es servicio funciones, minimamente 
                      deben estar conectados la entrada y salida de alg&uacute;n 
                      servicio externo.</p>
                    </div>
   				    <?php $messages->printAll()?>
					</td>
              </tr>
              <tr> 
                <td><hr /> 
                  
				  
				  
				  <table width="80%" border="0" align="center">
                    <tr> 
                      <td><div align="center"><strong>Conexiones</strong></div></td>
                    </tr>
                    <tr> 
                      <td>
					  	<form name="form1" id="form1" method="post" action="eliminar_connection.php">
					  		<div style="overflow:auto;width:100%;height:150px;" align="left">
								<select style= "width:150%;" name="id" id="id_externo" size="16" align="left">
//									<?
											echo getConnections();
											//echo "<option>Aca van las conexiones</option>";
//									?>
								</select>
							</div>  					    
                        	<div align="center"> 
                        		<input name="delete" type="submit" id="delete_interno" value="Eliminar" />
                        	</div>
						</form>
                    </tr>
                  </table>
                  <form action="agregar_conexion.php" name="form1" id="form1" method="post">
                    <div align="right"> 
                      <hr />
                      <p align="left"><strong>Connectar:</strong></p>
                      <table width="100%" border="0">
                        <tr> 
                          <td> <div align="right"><strong> 
                              <select name='desde' id='desde' ONCHANGE='LlenarCombos(this.options[this.selectedIndex].value, this.id)'>
<?php		
	echo "<option value='0'>Elige</option>";				
 	foreach ($externos as $s) 
	{
        echo "<option value='$s->id'>Ext-> $s->nombre -- Entrada</option>";
	}   

	foreach ($internos as $s) 
	{
        echo "<option value='$s->id'>Int-> $s->nombre -- Salida</option>";
	}                           

?>
                              </select>
                              </strong></div></td>
                          <td><div align="center"><strong>con</strong></div></td>
                          <td><strong> 
                            <select name='hasta' id='hasta' ONCHANGE='LlenarCombos(this.options[this.selectedIndex].value, this.id)'>
                              <?php						
	echo "<option value='0'>Elige</option>";
	foreach ($externos as $s) 
	{
        echo "<option value='$s->id'>Ext-> $s->nombre -- Salida</option>";
	}          
	
	foreach ($internos as $s) 
	{
        echo "<option value='$s->id'>Int-> $s->nombre -- Entrada</option>";
	}   
?>
                            </select>
                            </strong></td>
                        </tr>
                        <tr> 
                          <td><strong>Parametros:</strong></td>
                          <td><div align="center"></div></td>
                        </tr>
                        <tr> 
                          <td><div align="right"><strong> 
                              <select disabled="disabled" name="desde1" id="desde1">
                                <option value="0">Selecciona Opci&oacute;n...</option>
                              </select>
                              </strong></div></td>
                          <td><div align="center"><strong>al</strong></div></td>
                          <td><div align="left"><strong> 
                              <select disabled="disabled" name="hasta1" id="hasta1">
                                <option value="0">Selecciona opci&oacute;n...</option>
                              </select>
                              </strong></div></td>
                        </tr>
                        <tr> 
                          <td><div align="right"><strong> 
                              <select disabled="disabled" name="desde2" id="desde2">
                                <option value="0">Selecciona opci&oacute;n...</option>
                              </select>
                              </strong></div></td>
                          <td><div align="center"><strong>al</strong></div></td>
                          <td><div align="left"><strong> 
                              <select disabled="disabled" name="hasta2" id="hasta2">
                                <option value="0">Selecciona opci&oacute;n...</option>
                              </select>
                              </strong></div></td>
                        </tr>
                        <tr> 
                          <td height="26"><div align="right"><strong> 
                              <select disabled="disabled" name="desde3" id="desde3">
                                <option value="0">Selecciona opci&oacute;n...</option>
                              </select>
                              </strong></div></td>
                          <td><div align="center"><strong>al</strong></div></td>
                          <td><div align="left"><strong> 
                              <select disabled="disabled" name="hasta3" id="hasta3">
                                <option value="0">Selecciona opci&oacute;n...</option>
                              </select>
                              </strong></div></td>
                        </tr>
                      </table>
                      <p align="right"><strong>
                        <input name="agregar" type="submit" id="agregar" value="Agregar" />
                        </strong></p>
                      </div>
                  </form>
                  <p>&nbsp;</p>
 
              </tr>
            </table></td>
          </tr>
        </table></td>
  </tr>
	<tr>
		<td height="33" colspan="2"><table width="100%" height="33"  border="0" cellpadding="0" cellspacing="0">
          <tr>
            <td background="images/footer.gif">&nbsp;</td>
          </tr>
        </table></td>
  </tr>
</table>
<div align="center"><br />
</div>
</body>
</html>